home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0074_CD-ROM Dectection.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  7KB  |  224 lines

  1. {
  2.  JM>Would you happen to have any example code to determine if a drive is a
  3.  JM>hard disk, cd-rom, ramdrive etc. ?
  4.  
  5. Here is a unit that will at least tell you a little about the CD-ROM.   Not all
  6. MSCDEX functions are implemented, but enough to identify the CD-ROMS.
  7. }
  8. unit CDROM;
  9.  
  10. {$X+}   { Extended Syntax Rules }
  11.  
  12. interface
  13.  
  14. type
  15.   CDR_DL_ENTRY = record
  16.     UNITNO  : byte;
  17.     OFFSET  : word;
  18.     SEGMENT : word;
  19.   end;
  20.  
  21.   CDR_DL_BUFFER   = array[1..26] of CDR_DL_ENTRY;
  22.   CDR_DRIVE_UNITS = array[0..25] of byte;
  23.   CDR_VTOC        = array[1..2048] of byte;
  24.  
  25. { 00h } procedure CDR_GET_DRIVE_COUNT   (var COUNT, FIRST: word);
  26. { 01h } procedure CDR_GET_DRIVE_LIST    (var LIST: CDR_DL_BUFFER);
  27. { 02h } function  CDR_GET_COPR_NAME     (DRIVE: byte): string;
  28. { 03h } function  CDR_GET_ABSTRACT_NAME (DRIVE: byte): string;
  29. { 04h } function  CDR_GET_BIBLIO_NAME   (DRIVE: byte): string;
  30. { 05h Read VTOC }
  31. { 06h Reserved }
  32. { 07h Reserved }
  33. { 08h Absolute Disk Read }
  34. { 09h Absolute Disk Write }
  35. { 0ah Reserved }
  36. { 0bh } function  CDR_DRIVE_CHECK       (DRIVE: byte): boolean;
  37. { 0ch } function  CDR_VERSION: word;
  38. { 0dh } procedure CDR_GET_DRIVE_UNITS   (var BUFFER: CDR_DRIVE_UNITS);
  39. { 0eh Get or Set VDR }
  40. { 0fh Get Dir Entry }
  41. { 10h Send Device Request }
  42.  
  43. implementation
  44.  
  45. uses dos, strings;
  46.  
  47. const
  48.   CDROM_INTERRUPT = $2f;
  49.  
  50. var
  51.   REG : registers;
  52.  
  53. procedure CDR_GET_DRIVE_COUNT (var COUNT, FIRST: word);
  54. assembler;
  55.  
  56. { Returns the total number of CD-ROM Drives in the system }
  57. { and the logical drive number of the first drive.        }
  58.  
  59. { In a system that contains multiple CD-ROM Drives and is }
  60. { also networked, the CD-ROM drives might not be assigned }
  61. { as consecutive logical units.  See also MSCDEX Function }
  62. { 0Dh (Get CD-ROM Drive Letters)                          }
  63.  
  64. asm
  65.   mov ax, 1500h
  66.   xor bx, bx
  67.   int CDROM_INTERRUPT
  68.   les di, COUNT
  69.   mov es:[di], bx
  70.   les di, FIRST
  71.   mov es:[di], cx
  72. end;
  73.  
  74. procedure CDR_GET_DRIVE_LIST (var LIST: CDR_DL_BUFFER);
  75. assembler;
  76.  
  77. { Returns a driver unit identifier for each CD-ROM drive  }
  78. { in the system, along with the address of the header for }
  79. { the device driver that controls the drive.              }
  80.  
  81. { The driver unit code returned in the buffer is not the  }
  82. { systemwide logical drive identifier but is the relative }
  83. { unit for that particular driver.  For example if three  }
  84. { CD-ROM drivers are installed, each supporting one phy-  }
  85. { sical drive, the driver unit code in each 5 byte entry  }
  86. { will be 0.  The systemwide drive identifiers for each   }
  87. { CD-ROM unit can be obtained with MSCDEX Function 0Dh    }
  88. { (Get CD-ROM Drive Letters).                             }
  89.  
  90. asm
  91.   mov ax, 1501h
  92.   les bx, LIST
  93.   int CDROM_INTERRUPT
  94. end;
  95.  
  96. function  CDR_GET_COPR_NAME (DRIVE: byte): string;
  97.  
  98. { Returns the name of the copyright file from the volume  }
  99. { table of contents (VTOC) of the specified CD-ROM Drive. }
  100.  
  101. { CD-ROM Specs allow for a 31 character filename followed }
  102. { by a semicolon (;) and a 5 digit version number.        }
  103.  
  104. { On disks that comply with the High Sierra standard,     }
  105. { the filename has an MS-DOS compatable (8/3) format.     }
  106.  
  107. var
  108.   BUFFER : array[0..38] of char;
  109.  
  110. begin
  111.   REG.AX := $1502;
  112.   REG.CX := DRIVE;
  113.   REG.ES := seg(BUFFER);
  114.   REG.BX := ofs(BUFFER);
  115.   intr(CDROM_INTERRUPT, REG);
  116.   CDR_GET_COPR_NAME := strpas(BUFFER);
  117. end;
  118.  
  119. function  CDR_GET_ABSTRACT_NAME (DRIVE: byte): string;
  120.  
  121. { Returns the name of the abstract file from the volume   }
  122. { table of contents (VTOC) for the specified CD-ROM drive.}
  123.  
  124. { CD-ROM Specs allow for a 31 character filename followed }
  125. { by a semicolon (;) and a 5 digit version number.        }
  126.  
  127. { On disks that comply with the High Sierra standard,     }
  128. { the filename has an MS-DOS compatable (8/3) format.     }
  129.  
  130. var
  131.   BUFFER : array[0..38] of char;
  132.  
  133. begin
  134.   REG.AX := $1503;
  135.   REG.CX := DRIVE;
  136.   REG.ES := seg(BUFFER);
  137.   REG.BX := ofs(BUFFER);
  138.   intr(CDROM_INTERRUPT, REG);
  139.   CDR_GET_ABSTRACT_NAME := strpas(BUFFER);
  140. end;
  141.  
  142. function  CDR_GET_BIBLIO_NAME (DRIVE: byte): string;
  143.  
  144. { Returns the name if the bibliographic file from the     }
  145. { volume table of contents (VTOC) for the specified drive.}
  146.  
  147. { CD-ROM Specs allow for a 31 character filename followed }
  148. { by a semicolon (;) and a 5 digit version number.        }
  149.  
  150. { This function is provided for compatability with the    }
  151. { ISO-9660 standard.  A null string is returned for disks }
  152. { complying with the High Sierra standard.                }
  153.  
  154. var
  155.   BUFFER : array[0..38] of char;
  156.  
  157. begin
  158.   REG.AX := $1504;
  159.   REG.CX := DRIVE;
  160.   REG.ES := seg(BUFFER);
  161.   REG.BX := ofs(BUFFER);
  162.   intr(CDROM_INTERRUPT, REG);
  163.   CDR_GET_BIBLIO_NAME := strpas(BUFFER);
  164. end;
  165.  
  166. function CDR_DRIVE_CHECK (DRIVE: byte): boolean;
  167.  
  168. { Returns a code indicating whether a particular logical  }
  169. { unit is supported by the Microsoft CD-ROM Extensions    }
  170. { module (MSCDEX).                                        }
  171.  
  172. begin
  173.   REG.AX := $150b;
  174.   REG.BX := $0000;
  175.   REG.CX := DRIVE;
  176.   intr(CDROM_INTERRUPT, REG);
  177.   CDR_DRIVE_CHECK := (REG.AX <> $0000) and (REG.BX = $adad);
  178. end;
  179.  
  180. function  CDR_VERSION: word;
  181.  
  182. { Returns the version number of the Microsoft CD-ROM Extensions }
  183.  
  184. { The Major Version number is returned in the High Order byte   }
  185. { and the Minor Version Number is returned in the Lo order      }
  186. { byte.  IE if the MSCDEX Version is 2.10, this routine will    }
  187. { return $0210.                                                 }
  188.  
  189. begin
  190.   REG.AX := $150c;
  191.   REG.BX := $0000;
  192.   intr(CDROM_INTERRUPT, REG);
  193.  
  194.   { Version 1.0 Returns 0 instead of actual Version Number }
  195.   { So we will fix it so that this routine returns 1.0     }
  196.  
  197.   if REG.BX = 0 then begin
  198.     CDR_VERSION := $0100;
  199.   end else begin
  200.     CDR_VERSION := REG.BX;
  201.   end;
  202. end;
  203.  
  204. procedure CDR_GET_DRIVE_UNITS(var BUFFER: CDR_DRIVE_UNITS);
  205. assembler;
  206.  
  207. { Returns a list of the systemwide logical drive identifers     }
  208. { that are assigned to CD-ROM drives.                           }
  209.  
  210. { Upon return the buffer contains a series of 1 byte entries.   }
  211. { Each entry is a logical unit code assigned to a CD-ROM drive  }
  212. { (0 = A, 1 = B, etc); the units might not be consecutive.      }
  213.  
  214. { The number of valid entries can be determined by MSCDEX       }
  215. { function 00h.                                                 }
  216.  
  217. asm
  218.   mov ax, 150dh
  219.   les bx, BUFFER
  220.   int CDROM_INTERRUPT
  221. end;
  222.  
  223. end.
  224.